﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace FingerTip.Infrastructure
{
    public class Singleton<T> where T:class,new()
    {
        private static T _instance;
        private static readonly object SyncRoot = new object();

        public static T Instance
        {
            get
            {
                var instance = _instance;
                if (instance != null) return instance;
                lock (SyncRoot)
                {
                    instance = Volatile.Read(ref _instance) ?? new T();

                    Volatile.Write(ref _instance, instance);
                }

                return instance;
            }
        }
    }
}
